<?php

require_once ("includes/connect.php");
require_once ("includes/function.php");

$pet_id = $_REQUEST["pet_id"];

$db = new myDBS();
$Cur = new Currency;

$sql = "SELECT tbl_promise_borrow.*, pet_id "
        . " FROM tbl_pet_borrow, tbl_promise_borrow  "
        . " WHERE pet_id  = '$pet_id' "
        . " AND tbl_pet_borrow.borrow_id = tbl_promise_borrow.borrow_id ";

//echo $sql;
$result = $db->runSQL($sql);
$rows = $db->fetch_object($result);

// just require TCPDF instead of FPDF
//define('FPDF_FONTPATH','fpdf/font/');
require_once('fpdf/TCPDF/tcpdf.php');
require_once('fpdf/FPDI/fpdi.php');

class PDF extends FPDI {

    /**
     * "Remembers" the template id of the imported page
     */
    var $_tplIdx;

    /**
     * include a background template for every page
     */
    function Header() {
        if (is_null($this->_tplIdx)) {
            $this->numPages = $this->setSourceFile('form/form2.pdf');
            //$this->numPages = $this->setSourceFile($fullPathToFile);
            $this->_tplIdx = $this->importPage(1);
        }
        $this->useTemplate($this->_tplIdx);

        /*
          //$this->AddFont('THSarabunNew','','THSarabunNew.php');
          //$this->SetFont('THSarabunNew', '', 9);
          $this->SetTextColor(255);
          $this->SetXY(60.5, 24.8);
          $this->Cell(0, 8.6, "TCPDF and FPDI");
         */
    }

    function Footer() {
        
    }

}

// initiate PDF
$pdf = new PDF($orientation = 'P', $unit = 'mm', 'A4', $unicode = true, $encoding = 'UTF-8', $diskcache = false, $pdfa = false);
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
//$pdf->SetAutoPageBreak(true, 40);
$pdf->setFontSubsetting(false);

// add a page
$pdf->AddPage();

$vertical_align = 3;

//$pdf->AddFont('THSarabunNew','','THSarabunNew.php');
//$pdf->SetFont("freeserif", "", 12);
$pdf->SetFont('thsarabunb', 'B', 15);
// now write some text above the imported page
$pdf->SetXY(30, 27 + $vertical_align);
$pdf->Write(0, $_SESSION["lvl1"]);

//$pdf->SetXY(28, 33 + $vertical_align);
//$pdf->Write(0, $rows->budget_year);

$pdf->SetXY(92, 34 + $vertical_align);
$pdf->Write(0, $rows->pet_id);

//$pdf->SetXY(24, 41 + $vertical_align);
//$pdf->Write(0, $rows->panngan2_name);

//$elass = gen_account_id($rows->panngan2_id, $rows->panngan3_id, $rows->e_id);
//$pdf->SetXY(155, 48.5 + $vertical_align);
//$pdf->Write(0, $elass);

//$pdf->SetXY(84, 41 + $vertical_align);
//$pdf->Write(0, $rows->panngan3_name);

//$pdf->SetXY(155, 56 + $vertical_align);
//$pdf->Write(0, $elass);

//$pdf->SetXY(28, 47 + $vertical_align);
//$pdf->MultiCell(50, 10, $rows->expenses1_name, 0, '', 0, 0, '', '', true);
//
//$pdf->SetXY(90, 47 + $vertical_align);
//$pdf->Write(0, $rows->expenses2_name);
//
//$pdf->SetXY(90, 55 + $vertical_align);
//$pdf->Write(0, $rows->expenses3_name);

$pdf->SetXY(76, 69 + $vertical_align);
$pdf->Cell(41, 0, number_format($rows->borrow_amount, 2), 0, 0, 'R');

//$pdf->SetXY(120, 69 + $vertical_align);
//$pdf->MultiCell(90, 45, $_SESSION["lvl2"] . " ประจำ " . $rows->month_year, 0, '', 0, 1, '', '', true);


$pdf->SetXY(76, 105 + $vertical_align);
$pdf->Cell(41, 0, number_format($rows->borrow_amount, 2), 0, 0, 'R');

$pdf->SetXY(56, 111.5 + $vertical_align);
$pdf->Write(0, $Cur->bahtThai($rows->borrow_amount));


$pdf->SetXY(22, 168 + $vertical_align);
$pdf->Cell(39, 0, number_format($rows->borrow_amount, 2), 0, 0, 'C');

$pdf->SetXY(90, 168 + $vertical_align);
$pdf->Cell(39, 0, number_format($rows->borrow_amount, 2), 0, 0, 'C');

$pdf->SetXY(157, 168 + $vertical_align);
$pdf->Cell(39, 0, number_format($rows->borrow_amount, 2), 0, 0, 'C');

$pdf->SetXY(29, 232 + $vertical_align);
$pdf->Cell(36, 0, number_format($rows->borrow_amount, 2), 0, 0, 'C');

$pdf->SetXY(73, 232 + $vertical_align);
$pdf->Write(0, $Cur->bahtThai($rows->borrow_amount));


$pdf->Output('output_form1.pdf', 'I');
?>